﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;

namespace Barbar.Colonization.Core.Localization.XmlProvider {
  [XmlTypeAttribute(Namespace = XmlTranslatorFactory.NamespaceDescription)]
  public class Languages {
    private Collection<Definition> m_LanguageDefinitions = new Collection<Definition>();
    private Collection<Key> m_Keys = new Collection<Key>();

    [XmlArray(ElementName = "Definitions")]
    public Collection<Definition> LanguageDefinitions {
      get { return m_LanguageDefinitions; }
    }

    public Collection<Key> Keys {
      get { return m_Keys; }
    }

    internal TranslatorKey GetTranslatorKey(string code, Item item) {
      foreach (Definition definition in m_LanguageDefinitions)
        if (definition.Id == item.LanguageId)
          return new TranslatorKey(code, definition.Lcid);
      throw new ColonizationException(ExceptionTranslator.UnknownLanguageForKey, code);
    }
  }
}
